﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SuperKnowledgeDatabase2000Client
{
    /// <summary>
    /// logica for register user and UI logica for RegisterUser.xaml
    /// </summary>
    public partial class RegisterUser : Window
    {
        public RegisterUser()
        {
            InitializeComponent();
            txt_FirstName.Focus();
            txt_FirstName.SelectAll();
            txt_LastName.SelectAll();
        }

        /// <summary>
        /// loads the main window with the new userdata
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ShowMainWindow(object sender, RoutedEventArgs e)
        {
            if (txt_FirstName.Text.Length > 0 && txt_LastName.Text.Length > 0)
            {
                var mainWindow = new MainWindow();
                mainWindow.Show();
                Properties.Settings.Default.FirstName = txt_FirstName.Text;
                Properties.Settings.Default.LastName = txt_LastName.Text;
                Properties.Settings.Default.Save();
                this.Close();
            }
        }

        /// <summary>
        /// go to Mainwindow when user pushes the "Enter" button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnKeyDownHandler(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                ShowMainWindow(this, new RoutedEventArgs());
            }  
        }

        /// <summary>
        /// controls input, only letters are allowed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnTextBoxKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key < Key.D0 || e.Key > Key.D9)
            {
                e.Handled = false;
            }
            else
            {
                e.Handled = true;
            }
        }
    }
}
